/*
 * @lc app=leetcode.cn id=463 lang=javascript
 *
 * [463] 岛屿的周长
 */

// @lc code=start
/**
 * @param {number[][]} grid
 * @return {number}
 */
var islandPerimeter = function(grid) {
    let len=grid.length
    let count=0
    for(let i=0;i<len;i++){
        let sub=grid[i]
        let sub_len=grid[i].length
        for(let j=0;j<sub_len;j++){
            if(sub[j]===0)continue
            if(!grid[i][j-1]){
                count++
            }
            if(!grid[i][j+1]){
                count++
            }
            if(!grid[i-1]||!grid[i-1][j]){
                count++
            }
            if(!grid[i+1]||!grid[i+1][j]){
                count++
            }
        }
    }
    return count
};//此题还可用DFS深度遍历一下，依次判断上下左右BFS也可以
// @lc code=end

islandPerimeter([[0,1,0,0],
    [1,1,1,0],
    [0,1,0,0],
    [1,1,0,0]])